package cn.itcast.search.contriller;

import cn.itcast.hmall.dto.common.PageDTO;
import cn.itcast.hmall.dto.common.ResultDTO;
import cn.itcast.hmall.dto.search.SearchReqDTO;
import cn.itcast.hmall.pojo.item.ItemDoc;
import cn.itcast.search.servicer.Serviceiten;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/search")
public class Cotrler {
    @Autowired
    Serviceiten serviceiitens;
         //导入
    @GetMapping("/importItemData")
    public ResultDTO listAddItens() {
        return serviceiitens.listItemAdds();
    }
  //自动补全
    @GetMapping("/suggestion")
    public List<String> Searchompletion(@RequestParam("key") String key) {
        return serviceiitens.entrtSear(key);
    }

    //聚合
    @PostMapping("/filters")
    public Map<String, List<String>> searchReqDTO(@RequestBody SearchReqDTO searchReqDTO) {
        return serviceiitens.theAggregation(searchReqDTO);
    }

    //分页查询
    @PostMapping("/list")
    public PageDTO<ItemDoc> lists(@RequestBody SearchReqDTO searchReqDTO) {
        return serviceiitens.selectlist(searchReqDTO);

    }
}
